package com.zlll.winner.controller.mall;

import com.alibaba.fastjson.JSONObject;
import com.zlll.winner.business.model.mall.MallGoodsDetails;
import com.zlll.winner.business.service.mall.IMallGoodsDetailsService;
import com.zlll.winner.common.BaseController;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/mallGoodsDetail")
public class MallGoodsDetailController  extends BaseController {

    @Reference
    private IMallGoodsDetailsService goodsDetailsService;

    /**
     * 增加商品
     * @param mallGoodsDetails
     * @return
     */
    @PostMapping("add")
    public Object add(@RequestBody MallGoodsDetails mallGoodsDetails){
        mallGoodsDetails.setCreateUser(getUserId()+"");
        return goodsDetailsService.saveMallGoodsDetails(mallGoodsDetails);
    }

    /**
     * 获取列表
     * @return
     */
    @PostMapping("getMallGoodsDetails")
    public Object getMallGoodsDetails(@RequestBody JSONObject data){
        Integer pageNo = data.getInteger("pageNo") == null ? 1 : data.getInteger("pageNo");
        Integer pageSize = data.getInteger("pageSize") == null ? 20 : data.getInteger("pageSize");
        String goodsName = data.getString("goodsName");

        return goodsDetailsService.getMallGoodsDetails(goodsName,pageSize,pageNo);
    }

    /**
     *
     * @return
     */
    @PostMapping("edit/get/{id}")
    public Object getMallGoodsDetailsById(@PathVariable Long id){
        return goodsDetailsService.getById(id);
    }

    @PostMapping("edit")
    public Object edit(@RequestBody MallGoodsDetails mallGoodsDetails){
        mallGoodsDetails.setUpdateUser(getUserId()+"");
        return goodsDetailsService.editMallGoodsDetails(mallGoodsDetails);
    }

    /**
     *
     * @return
     */
    @PostMapping("delete/{id}")
    public Object deleteById(@PathVariable Long id){
        return goodsDetailsService.deleteById(id,getUserId());
    }

    /**
     * 获取发布列表
     * @param data
     * @return
     */
    @PostMapping("getReleaseMallGoodsDetails")
    public Object getReleaseMallGoodsDetails(@RequestBody JSONObject data){
        Integer pageNo = data.getInteger("pageNo") == null ? 1 : data.getInteger("pageNo");
        Integer pageSize = data.getInteger("pageSize") == null ? 20 : data.getInteger("pageSize");
        String goodsName = data.getString("goodsName");

        return goodsDetailsService.getReleaseMallGoodsDetails(goodsName,pageSize,pageNo);
    }
}
